<?php
class Gestff_EnseignantaformesController extends Zend_Controller_Action
{
	public function init(){
	
		$this->_helper->layout()->disableLayout();
		$this->_helper->layout()->setLayout("enseignantaformes");
	
		$activeNav =
		$this->view->navigation()->findByController('enseignantaformes');
		
	}
	
	public function inscriptionsessionAction(){
		$form=new Application_Form_Inscriptionsession();
		$this->view->form=$form;
		$this->view->titre="Inscription";
		$data=array();
		 
		
    	$data=array();
    	
    	if($this->_request->getParam("cin")){
    		$datadip_model=new Application_Model_MonDbTable_Participant();
    		$datadip=$datadip_model->getParticipant();
    		$datapopulate=array(
    				'cin'=>$datadip['cin']
    				,'nom'=>$datadip['nom']
    				,'etablissement'=>$datadip['etab']
    				,'prenom'=>$datadip['prenom' ]
    				,'date'=>$datadip['date_de_naissance' ]
    				,'adresse'=>$datadip['adresse' ]
    				,'mail'=>$datadip['mail' ]
    				,'tel'=>$datadip['telephone']
    				,'login'=>$datadip['login' ]
    				,'pass'=>$datadip['pass' ]
    				,'role'=>$datadip['role' ]
                     );
    		$form->populate($datapopulate);
    	}
    	
    	
    	
    	$this->view->form=$form;
    	 
    	if($this->_request->isPost()){
    		$formData = $this->_request->getPost();
    		 
    		if ($form->isValidPartial( $formData)) {
    			 
    			try{
    				$data=array(
    	
    						    'cin'=> $form->getValue('cin')
    							,'nom'=> $form->getValue('nom')
    							,'prenom'=> $form->getValue('prenom')
    						,'etablissement_id_etab'=> $form->getValue('etablissement')
    						,'date_de_naissance'=> $form->getValue('date' )
    							,'adresse'=> $form->getValue('adresse' )
    						    ,'email'=> $form->getValue('mail' )
    							,'telephone'=> $form->getValue('tel')
    							,'login'=> $form->getValue('login' )
    							,'password'=> $form->getValue('pass' )
    						,'role_id_role'=> 3
    							);
    					
    	
    					$etude=new Application_Model_DbTable_Participant();
    					if($this->_request->getParam("cin")){
    						$etude->update($data,'cin = '. $this->_request->getParam("cin")) ;
    					}else {
    						$etude->insert($data);
    					}
    					$this->_helper->redirector("afficheliste","coordinateur","gestff");
    	
    				}
    					
    			catch (Zend_Db_Exception $e) {
    				$this->view->messages = array('DbError' => $e->getMessage());
    				 
    			}
    			 
    		}
    	}
	}
	
	 
	
    public function indexAction()
    {
       echo "";
    }
 
    public function sessiondeformationAction(){
    	$this->view->titre="les sessions des formations";
    	$this->view->headTitle($this->view->title, 'PREPEND');
    	$model = new  Application_Model_MonDbTable_Sessionformation();
    	$this->view->model = $model->getFormation();
    
    }
    
    public function profilAction(){
    	$form=new Application_Form_Profil();
    	$this->view->headTitle($this->view->title, 'PREPEND');
    	$model1 = new  Application_Model_DbTable_Participant();
    	$this->view->model1 = $model1->fetchAll();
    }
    public function modifierAction(){
    	$form=new Application_Form_Profil();
    	$this->view->form=$form;
    	$this->view->titre="Modification de profil";
    	
    	$this->view->headTitle($this->view->title, 'PREPEND');
    	
    	
    	if($this->_request->getParam("id")){
    		$data_model=new Application_Model_DbTable_Participant();
    		$data=$data_model->fetchRow("cin=".$this->_request->getParam("id"))->toArray();
    	
    		$datapopulate=array(
    			 	'nom'=>$data['nom' ]
    				,'prenom'=>$data['prenom' ]
    				,'date'=>date("Y-m-d" ,strtotime($data['date_de_naissance' ]))
    				,'adresse'=>$data['adresse' ]
    				,'tel'=>$data['telephone' ]
    				,'mail'=>$data['email' ]
    				,'login'=>$data['login' ]
    				,'pass'=>$data['password' ]
    	
    		);
    		$form->populate($datapopulate);
    	}
    	
    	
    	$this->view->form=$form;
    	 
    	 
    	$dbtable=new Application_Model_DbTable_Participant();
    	if($this->_request->getParam("id")){
    		$dbtable->update($data,'cin = '. $this->_request->getParam("id")) ;
    	}else {
    		$dbtable->insert($data);
    	}
    	 
    	
    	}
    	
    	 
    	
    	    public function parcoursAction(){
    
    	$this->view->titre="les parcours";
    }
    
    public function evalsessionAction(){
    
    	$this->view->titre="Evaluation des sessions";
    }
    
    public function evalformationAction(){
    
    	$this->view->titre="Evaluation des formations";
    }
    public function activationsessionAction(){
    	$formData = $this->_request->getPost();
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	try{
    		$formsess= new Application_Model_DbTable_Participant();
    		$formsess->update(array('etat'=>$formData['val']),"cin=".$formData['id']);
    	}catch(Zend_Exception $e){
    		echo $e->getMessage();
    	}
    }
    	
}